package com.data.controller;

import java.util.Arrays;
import java.util.Map;

import com.data.entity.DataEntity;
import com.data.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.common.utils.PageUtils;
import com.common.utils.R;




@RestController
@RequestMapping("/data")
public class DataController {
    @Autowired
    private DataService dataService;

    /**
     * 列表x
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		DataEntity data = dataService.getById(id);

        return R.ok().put("data", data);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody DataEntity data){
		dataService.save(data);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody DataEntity data){
		dataService.updateById(data);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		dataService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
